import sys
import datetime

class ConsoleLogger:
    def __init__(self, log_level="INFO"):
        self.log_level = log_level

        # 定义日志级别对应的颜色
        self.log_colors = {
            "INFO": "\033[94m",  # 蓝色
            "WARNING": "\033[93m",  # 黄色
            "ERROR": "\033[91m",  # 红色
            "DEBUG": "\033[92m",  # 绿色
            "RESET": "\033[0m"  # 重置颜色
        }

    def log(self, message, level="INFO"):
        if self.log_level == "DEBUG" or level != "DEBUG":
            timestamp = datetime.datetime.now().strftime("%H:%M:%S")
            log_message = f"[{level}] {timestamp}: {message}"
            colored_log = f"{self.log_colors[level]}{log_message}{self.log_colors['RESET']}"
            print(colored_log)

    def info(self, message):
        self.log(message, level="INFO")

    def warning(self, message):
        self.log(message, level="WARNING")

    def error(self, message):
        self.log(message, level="ERROR")

    def debug(self, message):
        self.log(message, level="DEBUG")

log = ConsoleLogger(log_level="INFO")
